/*
 * refAnalyser.h
 *
 *  Created on: Dec 2, 2012
 *      Author: hxin
 */

#ifndef REFANALYSER_H_
#define REFANALYSER_H_

#include <fstream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <cstdlib>
#include "KmerHash.h"
#include "refHash.h"

using namespace std;

class hashStats {
public:
	hashStats();
	hashStats(const hashStats& rhs);
	~hashStats();

	void printStats();

	vector<int> LocLengthStat;
	unsigned long int totalLocLength;
	double avgLocLength;
};

class refAnalyser: public refHash {
public:
	//Constructor. Destructor
	refAnalyser();
	refAnalyser(string refFileName, int KmerSize, int maxError = 5);
	refAnalyser(const refAnalyser& rhs);
	~refAnalyser();
	refAnalyser& operator=(const refAnalyser& rhs);
	refHash* clone();

	//Load Reference into a set
	void loadHash(int chrNum);
	void unloadHash();
	vector<unsigned long long> query(string read);
	vector<unsigned long long> query(string read,
			vector<unsigned long int>& conductedAF);
	void genStat();
	void printStat();

	//Reserved for multiLvHT:
	//move the iterator to the beginning position
	void begin();
	//Test if the iterator has rolled to the end position
	bool end();
	//Roll the iterator to the next one.
	void next();
	//Return current iterator's string
	string getKmerString();
	//Prune the Kmer out
	void pruneKmer(string KmerString);

protected:
	void gotoChr(int chrNum);
	unsigned long int countChr(int chrNum);

	//Data:
	map<KmerHash, int, bool (*)(const KmerHash&, const KmerHash&)> chrHashData;
	string refFileName;
	ifstream refFile;
	int KmerSize;
	int maxError;

	//stats:
	hashStats refStat;
	vector<unsigned long int> conductedAF;

	//Reserved for multiLvHT:
	map<KmerHash, int, bool (*)(const KmerHash&, const KmerHash&)>::iterator HTIter;
};

#endif
